<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<h1>
	<fmt:message key="address.list.title" />
</h1>
<table class="search">
	<tr>

		<th><fmt:message key="address.form.city" /></th>
		<th><fmt:message key="address.form.street" /></th>
		<th><fmt:message key="address.form.streetNumber" /></th>
		<th><fmt:message key="address.form.postNumber" /></th>
	</tr>
	<c:forEach var="address" items="${list}" varStatus="status">
		<tr>
			<c:set var="addressFormId" value="address${status.index}" />

			<c:url var="editUrl" value="/address/form.html">
				<c:param name="id" value="${address.id}" />
			</c:url>

			<sec:authorize ifAllGranted="ROLE_ADMIN">
				<c:url var="deleteUrl" value="/address/delete.html" />
				<form id="${addressFormId}" action="${deleteUrl}" method="POST">
					<input id="id" name="id" type="hidden" value="${address.id}" />
				</form>
			</sec:authorize>


			<td>${address.city}</td>
			<td>${address.street}</td>
			<td>${address.streetNumber}</td>
			<td>${address.postNumber}</td>
			<td><a href='<c:out value="${editUrl}"/>'><fmt:message
						key="button.edit" /></a> <sec:authorize ifAllGranted="ROLE_ADMIN">
					<a href="javascript:document.forms['${addressFormId}'].submit();"><fmt:message
							key="button.delete" /></a>
				</sec:authorize></td>
		</tr>
	</c:forEach>
</table>